package com.kefan.reptilemanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kefan.reptilemanagement.common.entities.SysUserRole;
import com.kefan.reptilemanagement.common.errorHandler.BizException;
import com.kefan.reptilemanagement.mapper.SysUserRoleMapper;
import com.kefan.reptilemanagement.service.SysUserRoleService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sjj
 * @since 2021-10-17
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService {

    @Override
    public boolean add(SysUserRole sysUserRole) {
        QueryWrapper<SysUserRole> wrapper=new QueryWrapper<>();
        wrapper.eq("user_id",sysUserRole.getUserId());
        wrapper.eq("role_id",sysUserRole.getRoleId());
        SysUserRole old= getOne(wrapper);
        if(old!=null)
        {
            throw new BizException("用户已经有此权限！");
        }
        return save(sysUserRole);
    }
}
